package com.yuhuihui.common.utils.mail;

import org.springframework.beans.factory.annotation.Value;

/**
 * 邮箱配置类
 * @author yuhh
 * @date 2019/11/27 16:11
 */
public class MailConfig {

    /**
     * 邮件主机
     */
    static String MAIL_HOST;
    /**
     * 邮件主机端口
     */
    static Integer MAIL_PORT;
    /**
     * 邮件主机用户名
     */
    static String MAIL_USER_NAME;
    /**
     * 邮件主机授权码
     */
    static String MAIL_PASSWORD;
    /**
     * 发件方邮箱
     */
    static String MAIL_EMAIL_FROM;
    /**
     * 邮件发送超时时间
     */
    static String MAIL_TIMEOUT;
    /**
     * 邮件发送方昵称
     */
    static String MAIL_PERSONAL;

    /**
     * 是否发送
     */
    static Boolean IS_SEND;

    /**
     * 收件人
     */
    static String SEND_EMAIL;

    @Value("${mail.mailHost}")
    public void setMailHost(String mailHost) {
        MAIL_HOST = mailHost;
    }

    @Value("${mail.mailPort}")
    public void setMailPort(Integer mailPort) {
        MAIL_PORT = mailPort;
    }

    @Value("${mail.mailUserName}")
    public void setMailUserName(String mailUserName) {
        MAIL_USER_NAME = mailUserName;
    }

    @Value("${mail.mailPassword}")
    public void setMailPassword(String mailPassword) {
        MAIL_PASSWORD = mailPassword;
    }

    @Value("${mail.mailEmailFrom}")
    public void setMailEmailFrom(String mailEmailFrom) {
        MAIL_EMAIL_FROM = mailEmailFrom;
    }

    @Value("${mail.mailTimeout}")
    public void setMailTimeout(String mailTimeout) {
        MAIL_TIMEOUT = mailTimeout;
    }

    @Value("${mail.mailPersonal}")
    public void setMailPersonal(String mailPersonal) {
        MAIL_PERSONAL = mailPersonal;
    }

    @Value("${mail.isSend}")
    public void setIsSend(Boolean isSend) {
        IS_SEND = isSend;
    }

    @Value("${mail.sendEmail}")
    public void setSendEmail(String sendEmail) {
        SEND_EMAIL = sendEmail;
    }

    //    static{
//        init();
//    }
//
//    /**
//     * 初始化
//     */
//    private static void init() {
//        // 获取配置参数
//        Properties properties = PropertiesUtil.getProperties();
//        MAIL_HOST = properties.getProperty("mailHost");
//        MAIL_PORT = Integer.parseInt(properties.getProperty("mailPort"));
//        MAIL_USER_NAME = properties.getProperty("mailUsername");
//        MAIL_PASSWORD = properties.getProperty("mailPassword");
//        MAIL_EMAIL_FROM = properties.getProperty("mailFrom");
//        MAIL_TIMEOUT = properties.getProperty("mailTimeout");
//        try {
//            MAIL_PERSONAL = new String(properties.getProperty("personal").getBytes("ISO8859-1"), StandardCharsets.UTF_8);
//        } catch (UnsupportedEncodingException e) {
//            logger.error("邮件昵称编码转换出现异常");
//        }
//        IS_SEND = Boolean.valueOf(properties.getProperty("isSend"));
//        SEND_EMAIL = properties.getProperty("sendEmail");
//    }
}
